/*  BattGUI - First screen of Intelligent Battery Monitor 
  
        Copyright (C) 2009 Devendra Laulkar

        This program is free software: you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation version 2 of the License. 

        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.

        You should have received a copy of the GNU General Public License
        along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package com.intellBatt;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

public class BatGUI extends Activity {
	
	public static final int MENU_VIEW = 1;
	public static final int MENU_STOP = 2;
	public static final int MENU_SETTINGS = 3;
	private static final int MENU_DONATE = 4;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.start);
        startService(new Intent("com.IntelBat.services.BATT"));
    }
    
    public void onDestroy()
    {
    	//stopService(new Intent("com.IntelBat.LOC"));
    	super.onDestroy();
    }
    
    public boolean onCreateOptionsMenu(Menu menu) 
	{
		super.onCreateOptionsMenu(menu);
		MenuItem item;
		item = menu.add(0, MENU_VIEW,0, R.string.menuView);
		item.setIcon(android.R.drawable.ic_menu_info_details);

		item = menu.add(0, MENU_STOP,0, R.string.menuStop);
		item.setIcon(android.R.drawable.ic_menu_close_clear_cancel);

		item = menu.add(0, MENU_SETTINGS,0, R.string.menuSettings);
		item.setIcon(android.R.drawable.ic_menu_preferences);

		item = menu.add(0, MENU_DONATE,0, R.string.menuDonate);
		item.setIcon(android.R.drawable.ic_menu_view);

		return true;
	}

	public boolean onMenuItemSelected(int featureId, MenuItem item) 
	{
		super.onMenuItemSelected(featureId, item);
		switch(item.getItemId()) {
		case MENU_VIEW:
			viewLocations();
			break;
		case MENU_STOP:
			stopService(new Intent("com.IntelBat.services.BATT"));
			Toast.makeText(this, "Monitoring service stopped",
					Toast.LENGTH_SHORT).show();
			break;
		case MENU_SETTINGS:
			startActivity(new Intent(this,Settings.class));
			break;
			
		case MENU_DONATE:
//			Uri uri = Uri.parse("https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=5151699");
//			Intent i = new Intent("android.intent.action.VIEW", uri);
//			startActivity(i);
			displayAbout();
			break;
		}

		return true;
	}

	private void displayAbout() {
		new AlertDialog.Builder(this).setMessage(R.string.donate).
		setPositiveButton(android.R.string.ok, null).show();
	}

	private void viewLocations() {
		Intent i = new Intent(this, LocationViewer.class);
		startActivity(i);
	}

}